﻿using System;
using System.Collections.Generic;
using System.Text;

using Uber.Storage;
using Uber.HabboHotel.Items;
using Uber.HabboHotel.GameClients;
using Uber.Messages;
using Uber.HabboHotel.Rooms;
using System.Data;

namespace Uber.HabboHotel.Misc
{
    class ChatCommandHandler
    {
        public static Boolean Parse(GameClient Session, string Input)
        {
            if (Input.Length <= 0 || Input == "")
            {
                return false;
            }

            string[] Params = Input.Split(' ');

            string TargetUser = null;
            GameClient TargetClient = null;
            Room TargetRoom = null;
            RoomUser TargetRoomUser = null;

            switch (Params[0].ToLower())
            {
                #region Debugging/Development
                case "userinfo":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    string Username = null;

                    if ((Username = Params[1]) == null) { SendChatMessage(Session, "The username you've typed in is invalid!"); return true; }

                    TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(Username); if (TargetClient == null) { SendChatMessage(Session,"This user is'nt online!"); return true; }

                    StringBuilder Builderer = new StringBuilder();

                    Builderer.AppendLine("User details of: " + TargetClient.GetHabbo().Username);
                    Builderer.AppendLine("Credits: " + TargetClient.GetHabbo().Credits);
                    Builderer.AppendLine("Pixels: " + TargetClient.GetHabbo().ActivityPoints);
                    Builderer.AppendLine("Rank: " + TargetClient.GetHabbo().Rank);
                    Builderer.AppendLine("Motto: " + TargetClient.GetHabbo().Motto);
                    Builderer.AppendLine("Respect: " + TargetClient.GetHabbo().Respect);
                    Builderer.AppendLine((TargetClient.GetHabbo().IsUltraVip) ? "Ultra-Vip: true" : "Ultra-Vip: false");
                    Builderer.AppendLine("Minutes-Online: " + TargetClient.GetHabbo().GetTotalMinutes);

                    Session.SendMotd(Convert.ToString(Builderer));

                    return true;

                case "whosonline":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    var UserList = UberEnvironment.GetGame().GetClientManager().Clients;
                    var UsersToDisplay = new List<string>();
                    StringBuilder Builder = new StringBuilder();

                    Builder.AppendLine("These Users are online:");

                    for (int i = 0; i < UserList.Count; i++)
                    {
                        GameClient Client = UserList[i]; if (Client == null) { continue; }
                        UsersToDisplay.Add(Client.GetHabbo().Username);
                    }

                    for (int i = 0; i < UsersToDisplay.Count; i++)
                    {
                        Builder.AppendLine((UsersToDisplay[i] != null) ? "- " + UsersToDisplay[i] : "- Empty username.");
                    }

                    Session.SendMotd(Convert.ToString(Builder));

                    return true;
                case "addbadge":
                    {
                        string Badge = "";
                        int slot = 1;

                        try { Badge = Params[1]; }
                        catch { return false; }

                        try { slot = Convert.ToInt32(Params[2]); }
                        catch { Session.SendNotif("Slot (Second Arguement) Needs to be a number (1 - 5)"); return true;}
                        if (slot < 1 || slot > 5) { Session.SendNotif("Slot (Second Arguement) Needs to be a number (1 - 5)"); return true; }

                        if (Session.GetHabbo().Rank <= 1 || Badge == "" || Badge.Length < 3)
                        {
                            return false;
                        }

                        Session.GetHabbo().GetBadgeComponent().GiveBadge(Badge, true);
                        Session.GetHabbo().GetBadgeComponent().SetBadgeSlot(Badge, slot);

                        SendChatMessage(Session, "Badge given: " + Badge);

                        return true;
                    }
                case "brb":
                    {
                        if (!Session.GetHabbo().IsUltraVip)
                        {
                            SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                            return false;
                        }

                        TargetRoom = Session.GetHabbo().CurrentRoom;
                        TargetRoomUser = TargetRoom.GetRoomUserByHabbo(Session.GetHabbo().Username);

                        if (TargetRoom == null || TargetRoomUser == null) { return false; }

                        if (!Session.GetHabbo().IsBRB)
                        {
                            Session.GetHabbo().IsBRB = true;

                            TargetRoom.ApplyUserEffect(TargetRoomUser, 10, true);

                            ReloadRoomUser(TargetRoomUser, TargetRoom, Session, true);

                            SendChatMessage(Session, "You're now BRB, enjoy it!");
                        }
                        else if (Session.GetHabbo().IsBRB)
                        {
                            Session.GetHabbo().IsBRB = false;

                            TargetRoom.ApplyUserEffect(TargetRoomUser, 0, true);

                            ReloadRoomUser(TargetRoomUser, TargetRoom, Session, false);

                            SendChatMessage(Session, "You're now back, enjoy it!");
                        }

                        return true;
                    }

                case "update_quests":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetQuestManager().InitQuests();
                        return true;
                    }

                    return false;

                case "update_inventory":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        Session.GetHabbo().GetInventoryComponent().UpdateItems(true);
                        return true;
                    }

                    return false;

                case "update_bots":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetBotManager().LoadBots();
                        return true;
                    }

                    return false;

                case "update_catalog":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetCatalog().Initialize();
                        UberEnvironment.GetGame().GetClientManager().BroadcastMessage(new ServerMessage(441));

                        return true;
                    }

                    return false;

                case "update_config":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetGameConfiguration().UpdateConfig();
                        Session.SendNotif("Configuration has been reloaded.");

                        return true;
                    }

                    return false;

                case "update_navigator":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetNavigator().Initialize();
                        Session.SendNotif("Navigator has been updated.");
                        return true;
                    }

                    return false;

                case "t":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                        if (TargetRoom == null)
                        {
                            return false;
                        }

                        TargetRoomUser = TargetRoom.GetRoomUserByHabbo(Session.GetHabbo().Id);

                        if (TargetRoomUser == null)
                        {
                            return false;
                        }

                        Session.SendNotif("X: " + TargetRoomUser.X + " - Y: " + TargetRoomUser.Y + " - Z: " + TargetRoomUser.Z + " - Rot: " + TargetRoomUser.RotBody);

                        return true;
                    }

                    return false;

                case "override":

                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                        if (TargetRoom == null)
                        {
                            return false;
                        }

                        TargetRoomUser = TargetRoom.GetRoomUserByHabbo(Session.GetHabbo().Id);

                        if (TargetRoomUser == null)
                        {
                            return false;
                        }

                        if (TargetRoomUser.AllowOverride)
                        {
                            TargetRoomUser.AllowOverride = false;
                            SendChatMessage(Session, "Walking override has been disabled.");
                        }
                        else
                        {
                            TargetRoomUser.AllowOverride = true;
                            SendChatMessage(Session, "Walking override has been enabled.");
                        }

                        return true;
                    }

                    return false;

                case "update_defs":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetItemManager().LoadItems();
                        Session.SendNotif("Item defenitions reloaded successfully.");
                        return true;
                    }

                    return false;

                case "blockfriends":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                    {
                        if (Session.GetHabbo().BlockNewFriends)
                        {
                            dbClient.ExecuteQuery("UPDATE users SET block_newfriends = '0' WHERE id = '" + Session.GetHabbo().Id + "' LIMIT 1");
                            Session.GetHabbo().BlockNewFriends = false;
                            SendChatMessage(Session, "Your friend requests has been enabled.");
                        }
                        else
                        {
                            dbClient.ExecuteQuery("UPDATE users SET block_newfriends = '1' WHERE id = '" + Session.GetHabbo().Id + "' LIMIT 1");
                            Session.GetHabbo().BlockNewFriends = true;
                            SendChatMessage(Session, "Your friend requests has been disabled.");
                        }
                    }
                    return true;

                case "setmax":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                        if (TargetRoom != null)
                        {
                            int usersMax;
                            if (int.TryParse(Params[1], out usersMax))
                            {
                                TargetRoom.UsersMax = usersMax;
                                SendChatMessage(Session, "Room limit has been set to: " + usersMax);
                                return true;
                            }
                        }
                    }

                    return false;
                #endregion

                #region General Commands
                case "staff":
                    Session.SendNotif("Admins:" + "\r\n" +
                                        "  KT, Fox and iTony " + "\r\n" +
                                       "Mods:" + "\r\n" +
                                        "  Aiwa, Goopchick, Cranavvo, Ayrton and" + "\r\n" + "  Kittehlols" + "\r\n" +
                                       "Management:" + "\r\n" +
                                        "  Volundr, and the most import of all," + "\r\n" + "  The Great Rusty!");
                    return true;
                    break;

                case "motto":
                    string mot = "";
                    if (Params.Length == 1) { return false; }
                    for(int i = 1; i < Params.Length; i++) mot += " " + Params[i];
                    mot = mot.Substring(1);
                    Session.GetHabbo().Motto = mot;
                    using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                    {
                        dbClient.ExecuteQuery("UPDATE users SET motto='" + mot + "' WHERE username='" + Session.GetHabbo().Username + "'");
                    }
                    ChatCommandHandler.ReloadRoomUser(UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId).GetRoomUserByHabbo(Session.GetHabbo().Id),
                                                      UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId),
                                                      Session, false);
                    return true;
                    break;

                case "setpaidgate":
                    TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);
                    if (TargetRoom != null && TargetRoom.CheckRights(Session, true))
                    {
                        int amount;
                        try
                        {
                            amount = Convert.ToInt32(Params[1]);
                        }
                        catch (Exception e)
                        {
                            Session.SendNotif("Make sure you use a number for this command!");
                            break;
                        }

                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            dbClient.ExecuteQuery("UPDATE rooms SET paidGateAmount='" + amount + "' WHERE id='" + TargetRoom.RoomId + "'");
                            SendChatMessage(Session, "Paidgate amount set succesfully!");
                        }
                    }
                    return true;
                    break;

                case "paidgate":
                    TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);
                    if (TargetRoom != null)
                    {
                        int amount;
                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            amount = Convert.ToInt32(dbClient.ReadDataRow("SELECT * FROM rooms WHERE id='" + TargetRoom.RoomId + "'")["paidGateAmount"]);
                            SendChatMessage(Session, "The amount for a paid gate in this room is " + amount + ".");
                        }
                    }
                    return true;
                    break;

                case "setnumbers":
                    if (Params.Length == 8)
                    {
                        bool flag = true;
                        try
                        {
                            for (int i = 1; i < 8; i++)
                            {
                                int num = Convert.ToInt32(Params[i]);
                                if (num < 0 || num > 99) { Session.SendNotif("Numbers are between 0 and 99"); return true; }
                            }
                        }
                        catch (Exception e)
                        {
                            flag = false;
                        }

                        if (!flag) { Session.SendNotif("Only numbers allowed in the lottery."); break; }
                        else
                        {
                            string numbers = "";
                            for (int i = 1; i < 8; i++) { numbers += " " + Params[i]; }
                            LotteryManager.AddTicket(Session.GetHabbo().Username, numbers);
                            SendChatMessage(Session, "You have set your numbers. Good Luck!");
                        }
                    }
                    else
                    {
                        Session.SendNotif("Please only submit seven numbers!");
                    }

                    return true;
                    break;

                case "pickall":

                    TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                    if (TargetRoom != null && TargetRoom.CheckRights(Session, true))
                    {
                        var ToRemove = new List<RoomItem>();

                        ToRemove.AddRange(TargetRoom.Items);

                        foreach (RoomItem Item in ToRemove)
                        {
                            TargetRoom.RemoveFurniture(Session, Item.Id, false);
                            Session.GetHabbo().GetInventoryComponent().AddItem(Item.Id, Item.BaseItem, Item.ExtraData, false);
                        }

                        Session.GetHabbo().GetInventoryComponent().UpdateItems(true);
                        return true;
                    }

                    return false;

                case "unload":

                    TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                    if (TargetRoom != null && TargetRoom.CheckRights(Session, true))
                    {
                        UberEnvironment.GetGame().GetRoomManager().UnloadRoom(TargetRoom.RoomId);
                        return true;
                    }

                    return false;

                case "moonwalk":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                    if (TargetRoom == null)
                    {
                        return false;
                    }

                    TargetRoomUser = TargetRoom.GetRoomUserByHabbo(Session.GetHabbo().Id);

                    if (TargetRoomUser == null)
                    {
                        return false;
                    }

                    if (TargetRoomUser.WalkBackwards)
                    {
                        TargetRoomUser.WalkBackwards = false;
                        SendChatMessage(Session, "You will now walk normally.");
                    }
                    else
                    {
                        TargetRoomUser.WalkBackwards = true;
                        SendChatMessage(Session, "You will now walk backwards.");
                    }

                    return true;

                case "teleport":

                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                        if (TargetRoom == null)
                        {
                            return false;
                        }

                        TargetRoomUser = TargetRoom.GetRoomUserByHabbo(Session.GetHabbo().Id);

                        if (TargetRoomUser == null)
                        {
                            return false;
                        }

                        if (TargetRoomUser.TeleportMode)
                        {
                            TargetRoomUser.TeleportMode = false;
                            SendChatMessage(Session, "Teleport mode disabled.");
                        }
                        else
                        {
                            TargetRoomUser.TeleportMode = true;
                            SendChatMessage(Session, "Teleport mode enabled.");
                        }

                        return true;
                    }

                    return false;  


                case "uptime":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    DateTime Now = DateTime.Now;
                    TimeSpan TimeUsed = Now - UberEnvironment.ServerStarted;

                    Session.SendNotif("Server is running for: " + TimeUsed.Days + " day(s), " + TimeUsed.Hours + " hour(s) and " + TimeUsed.Minutes + " minute(s)");
                    return true;

                case "info":
                case "details":
                case "about":

                    Session.SendNotif("This server is proudly powered by uberEmulator.\nCopyright (c) 2009, Roy 'Meth0d'\n\nhttp://www.meth0d.org", "http://www.meth0d.org/uber/");

                    return true;

                case "empty":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    Session.GetHabbo().GetInventoryComponent().ClearItems();
                    SendChatMessage(Session, "Your inventory items has been emptied.");

                    return true;

                case "emptypets":

                    if (!Session.GetHabbo().IsUltraVip)
                    {
                        SendChatMessage(Session, "Buy Ultra VIP to use this command!");
                        return false;
                    }

                    Session.GetHabbo().GetInventoryComponent().ClearPets();
                    SendChatMessage(Session, "Your pets from your inventory have been deleted.");

                    return true;

                #endregion

                #region Moderation Commands
                case "force_lottery":
                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        UberEnvironment.GetGame().GetPixelManager().lm.Update(true);
                        SendChatMessage(Session, "Lottery completed");
                        return true;
                    }
                    break;

                case "addrotw":
                    int rotw_cat = 3;
                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        Room target = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);
                        if (target == null) { Session.SendNotif("Please enter a room before using this command"); return true; }
                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            DataRow row = dbClient.ReadDataRow("SELECT * FROM rooms WHERE id='" + target.RoomId + "'");
                            dbClient.ExecuteQuery("UPDATE rooms SET old_category='" + row["category"] + "' WHERE id='" + target.RoomId + "'");
                            dbClient.ExecuteQuery("UPDATE rooms SET category='" + rotw_cat + "' WHERE id='" + target.RoomId + "'");
                            SendChatMessage(Session, "Added succesfully");
                        }
                    }
                    else
                    {
                        Session.SendNotif("How dare you use this command! You're trying to cheat, aren't you!");
                    }
                    return true;
                    break;

                case "removerotw":
                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        Room target = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);
                        if (target == null) { Session.SendNotif("Please enter a room before using this command"); return true; }

                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            DataRow row = dbClient.ReadDataRow("SELECT * FROM rooms WHERE id='" + target.RoomId + "'");
                            dbClient.ExecuteQuery("UPDATE rooms SET category='" + row["old_category"] + "' WHERE id='" + target.RoomId + "'");
                            dbClient.ExecuteQuery("UPDATE rooms SET old_category='" + "0" + "' WHERE id='" + target.RoomId + "'");
                            SendChatMessage(Session, "Removed succesfully");
                        }
                    }
                    else
                    {
                        Session.SendNotif("Never gonna give you up. Never gonna let you down. Never gonna let you use this command without Access!");
                    }
                    return true;
                    break;

                case "resetrotw":
                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            DataTable data = dbClient.ReadDataTable("SELECT * FROM rooms WHERE category='" + "3" + "'");
                            foreach (DataRow row in data.Rows)
                            {
                                dbClient.ExecuteQuery("UPDATE rooms SET category='" + row["old_category"] + "' WHERE id='" + row["id"] + "'");
                                dbClient.ExecuteQuery("UPDATE rooms SET old_category='0' WHERE id='" + row["id"] + "'");
                            }
                            SendChatMessage(Session, "Resetting Complete");
                        }
                    }
                    else
                    {
                        Session.SendNotif("You lost the game");
                    }
                    return true;
                    break;

                case "muteroom":
                    {
                        if (Session.GetHabbo().HasFuse("fuse_mod"))
                        {
                            Room Room = Session.GetHabbo().CurrentRoom;

                            if (Room != null)
                            {
                                if (!Room.IsMuted)
                                {
                                    Room.IsMuted = true;
                                    Session.SendNotif("Room Muted");
                                }
                                else if (Room.IsMuted)
                                {
                                    Room.IsMuted = false;
                                    Session.SendNotif("Room unMuted");
                                }
                            }

                            return true;
                        }
                    }
                    return false;

                case "invisible":

                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        if (Session.GetHabbo().SpectatorMode)
                        {
                            Session.GetHabbo().SpectatorMode = false;
                            Session.SendNotif("Spectator mode disabled. Reload the room to apply changes.");
                        }
                        else
                        {
                            Session.GetHabbo().SpectatorMode = true;
                            Session.SendNotif("Spectator mode enabled. Reload the room to apply changes.");
                        }

                        return true;
                    }

                    return false;

                case "appearoffline":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        if (Session.GetHabbo().GetMessenger().AppearOffline)
                        {
                            Session.GetHabbo().GetMessenger().AppearOffline = false;
                            Session.GetHabbo().GetMessenger().OnStatusChanged(true);
                            Session.SendNotif("You are now back online to everyone on messenger.");
                        }
                        else
                        {
                            Session.GetHabbo().GetMessenger().AppearOffline = true;
                            Session.GetHabbo().GetMessenger().OnStatusChanged(true);
                            Session.SendNotif("You are now temporarily appear offline to everyone on messenger.");
                        }
                        return true;
                    }

                    return false;

                case "unloadid":
                    if (Session.GetHabbo().HasFuse("fuse_admin"))
                    {
                        uint RoomId;
                        if (uint.TryParse(Params[1], out RoomId))
                        {
                            if (UberEnvironment.GetGame().GetRoomManager().IsRoomLoaded(RoomId))
                            {
                                UberEnvironment.GetGame().GetRoomManager().UnloadRoom(RoomId);
                                return true;
                            }
                            else
                            {
                                Session.SendNotif("This room is not loaded, unable to unload.");
                                return true;
                            }
                        }
                        return false;
                    }

                    return false;

                case "ha":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        string Notice = Input.Substring(3);
                        ServerMessage HotelAlert = new ServerMessage(139);
                        HotelAlert.AppendStringWithBreak("Message from Hotel Management:\r\n" + Notice + "\r\n- " + Session.GetHabbo().Username);
                        UberEnvironment.GetGame().GetClientManager().BroadcastMessage(HotelAlert);
                        SendChatMessage(Session, "You sent out a hotel alert, abuse of this command will result in punishment!");

                        return true;
                    }
                    return false;

                case "msgstaff":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        string Notice = Input.Substring(3);
                        ServerMessage StaffMessage = new ServerMessage(139);
                        StaffMessage.AppendStringWithBreak("Message from Staff User: " + Session.GetHabbo().Username + "\r\n" + Notice);
                        UberEnvironment.GetGame().GetClientManager().BroadcastMessage(StaffMessage, "fuse_mod");
                        return true;
                    }
                    return false;

                case "credits":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(Params[1]);
                        if (TargetClient != null)
                        {
                            int creditsToAdd;
                            if (int.TryParse(Params[2], out creditsToAdd))
                            {
                                if (creditsToAdd > 5000 || Session.GetHabbo().Credits >= 25000)
                                {
                                    Session.SendNotif("You cannot add that amount of credits to your account!");
                                    return true;
                                }
                                TargetClient.GetHabbo().Credits = TargetClient.GetHabbo().Credits + creditsToAdd;
                                TargetClient.GetHabbo().UpdateCreditsBalance(true);
                                TargetClient.SendNotif(Session.GetHabbo().Username + " has awarded you " + creditsToAdd.ToString() + " credits!");
                                Session.SendNotif("Credit balance updated successfully.");
                                return true;
                            }
                            else
                            {
                                Session.SendNotif("Please enter a valid amount of credits.");
                                return true;
                            }
                        }
                        else
                        {
                            Session.SendNotif("User could not be found.");
                            return true;
                        }
                    }
                    return false;

                case "pixels":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(Params[1]);
                        if (TargetClient != null)
                        {
                            int creditsToAdd;
                            if (int.TryParse(Params[2], out creditsToAdd))
                            {
                                if (creditsToAdd > 5000 || Session.GetHabbo().ActivityPoints >= 25000)
                                {
                                    Session.SendNotif("You cannot add that amount of pixels to your account!");
                                    return true;
                                }
                                TargetClient.GetHabbo().ActivityPoints = TargetClient.GetHabbo().ActivityPoints + creditsToAdd;
                                TargetClient.GetHabbo().UpdateActivityPointsBalance(true);
                                TargetClient.SendNotif(Session.GetHabbo().Username + " has awarded you " + creditsToAdd.ToString() + " pixels!");
                                Session.SendNotif("Pixel balance updated successfully.");
                                return true;
                            }
                            else
                            {
                                Session.SendNotif("Please enter a valid amount of pixels.");
                                return true;
                            }
                        }
                        else
                        {
                            Session.SendNotif("User could not be not found.");
                            return true;
                        }
                    }
                    return false;

                case "ban":

                    if (Session.GetHabbo().HasFuse("fuse_ban"))
                    {
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(Params[1]);

                        if (TargetClient == null)
                        {
                            Session.SendNotif("User not found.");
                            return true;
                        }

                        if (TargetClient.GetHabbo().Rank >= Session.GetHabbo().Rank)
                        {
                            Session.SendNotif("You are not allowed to ban that user.");
                            return true;
                        }

                        int BanTime = 0;

                        try
                        {
                            BanTime = int.Parse(Params[2]);
                        }
                        catch (FormatException) { }

                        if (BanTime <= 600)
                        {
                            Session.SendNotif("Ban time is in seconds and must be at least than 600 seconds (ten minutes). For more specific preset ban times, use the mod tool.");
                        }

                        UberEnvironment.GetGame().GetBanManager().BanUser(TargetClient, Session.GetHabbo().Username, BanTime, MergeParams(Params, 3), false);
                        return true;
                    }

                    return false;

                case "superban":

                    if (Session.GetHabbo().HasFuse("fuse_superban"))
                    {
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(Params[1]);

                        if (TargetClient == null)
                        {
                            Session.SendNotif("User not found.");
                            return true;
                        }

                        if (TargetClient.GetHabbo().Rank >= Session.GetHabbo().Rank)
                        {
                            Session.SendNotif("You are not allowed to ban that user.");
                            return true;
                        }

                        UberEnvironment.GetGame().GetBanManager().BanUser(TargetClient, Session.GetHabbo().Username, 360000000, MergeParams(Params, 2), false);
                        return true;
                    }

                    return false;

                case "roomkick":

                    if (Session.GetHabbo().HasFuse("fuse_roomkick"))
                    {
                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                        if (TargetRoom == null)
                        {
                            return false;
                        }

                        bool GenericMsg = true;
                        string ModMsg = MergeParams(Params, 1);

                        if (ModMsg.Length > 0)
                        {
                            GenericMsg = false;
                        }

                        var UsersToKick = new List<RoomUser>();

                        foreach (RoomUser RoomUser in TargetRoom.UserList)
                        {
                            if (RoomUser.GetClient().GetHabbo().Rank >= Session.GetHabbo().Rank)
                            {
                                continue;
                            }

                            if (!GenericMsg)
                            {
                                RoomUser.GetClient().SendNotif("You have been kicked by an moderator: " + ModMsg);
                            }

                            UsersToKick.Add(RoomUser);
                        }

                        foreach (RoomUser RoomUser in UsersToKick)
                        {
                            TargetRoom.RemoveUserFromRoom(RoomUser.GetClient(), true, GenericMsg);
                        }

                        return true;
                    }

                    return false;

                case "roomalert":

                    if (Session.GetHabbo().HasFuse("fuse_roomalert"))
                    {
                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);

                        if (TargetRoom == null)
                        {
                            return false;
                        }

                        string Msg = MergeParams(Params, 1);

                        foreach (RoomUser RoomUser in TargetRoom.UserList)
                        {
                            RoomUser.GetClient().SendNotif(Msg);
                        }

                        return true;
                    }

                    return false;

                case "mute":

                    if (Session.GetHabbo().HasFuse("fuse_mute"))
                    {
                        TargetUser = Params[1];
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(TargetUser);

                        if (TargetClient == null || TargetClient.GetHabbo() == null)
                        {
                            Session.SendNotif("Could not find user: " + TargetUser);
                            return true;
                        }

                        if (TargetClient.GetHabbo().Rank >= Session.GetHabbo().Rank)
                        {
                            Session.SendNotif("You are not allowed to (un)mute that user.");
                            return true;
                        }

                        TargetClient.GetHabbo().Mute();
                        return true;
                    }

                    return false;

                case "unmute":

                    if (Session.GetHabbo().HasFuse("fuse_mute"))
                    {
                        TargetUser = Params[1];
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(TargetUser);

                        if (TargetClient == null || TargetClient.GetHabbo() == null)
                        {
                            Session.SendNotif("Could not find user: " + TargetUser);
                            return true;
                        }

                        if (TargetClient.GetHabbo().Rank >= Session.GetHabbo().Rank)
                        {
                            Session.SendNotif("You are not allowed to (un)mute that user.");
                            return true;
                        }

                        TargetClient.GetHabbo().Unmute();
                        return true;
                    }

                    return false;

                case "alert":

                    if (Session.GetHabbo().HasFuse("fuse_alert"))
                    {
                        TargetUser = Params[1];
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(TargetUser);

                        if (TargetClient == null)
                        {
                            Session.SendNotif("Could not find user: " + TargetUser);
                            return true;
                        }

                        TargetClient.SendNotif(MergeParams(Params, 2), Session.GetHabbo().HasFuse("fuse_admin"));
                        return true;
                    }

                    return false;

                case "softkick":
                case "kick":

                    if (Session.GetHabbo().HasFuse("fuse_kick"))
                    {
                        TargetUser = Params[1];
                        TargetClient = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(TargetUser);

                        if (TargetClient == null)
                        {
                            Session.SendNotif("Could not find user: " + TargetUser);
                            return true;
                        }

                        if (Session.GetHabbo().Rank <= TargetClient.GetHabbo().Rank)
                        {
                            Session.SendNotif("You are not allowed to kick that user.");
                            return true;
                        }

                        if (TargetClient.GetHabbo().CurrentRoomId < 1)
                        {
                            Session.SendNotif("That user is not in a room and can not be kicked.");
                            return true;
                        }

                        TargetRoom = UberEnvironment.GetGame().GetRoomManager().GetRoom(TargetClient.GetHabbo().CurrentRoomId);

                        if (TargetRoom == null)
                        {
                            return true;
                        }

                        TargetRoom.RemoveUserFromRoom(TargetClient, true, false);

                        if (Params.Length > 2)
                        {
                            TargetClient.SendNotif("A moderator has kicked you from the room for the following reason: " + MergeParams(Params, 2));
                        }
                        else
                        {
                            TargetClient.SendNotif("A moderator has kicked you from the room.");
                        }

                        return true;
                    }

                    return false;
                #endregion
            }

            return false;
        }

        public static string MergeParams(string[] Params, int Start)
        {
            StringBuilder MergedParams = new StringBuilder();

            for (int i = 0; i < Params.Length; i++)
            {
                if (i < Start)
                {
                    continue;
                }

                if (i > Start)
                {
                    MergedParams.Append(" ");
                }

                MergedParams.Append(Params[i]);
            }

            return MergedParams.ToString();
        }

        public static void SendChatMessage(GameClient Session, string Message)
        {
            ServerMessage TellMsg = new ServerMessage();
            TellMsg.Init(25);
            TellMsg.AppendInt32(Session.GetHabbo().CurrentRoom.GetRoomUserByHabbo(Session.GetHabbo().Username).VirtualId);
            TellMsg.AppendStringWithBreak(Message);
            TellMsg.AppendBoolean(false);
            Session.GetConnection().SendMessage(TellMsg);
        }

        public static void ReloadRoomUser(RoomUser User, Room Room, GameClient Session, Boolean BRB)
        {
            if (User == null || Room == null || Session == null) { return; }

            ServerMessage RoomUpdate = new ServerMessage(266);
            RoomUpdate.AppendInt32(User.VirtualId);
            RoomUpdate.AppendStringWithBreak(Session.GetHabbo().Look);
            RoomUpdate.AppendStringWithBreak(Session.GetHabbo().Gender.ToLower());
            RoomUpdate.AppendStringWithBreak((BRB) ? "BRB - " + Session.GetHabbo().Motto : Session.GetHabbo().Motto);
            RoomUpdate.AppendInt32(Session.GetHabbo().GetAchievementScore());
            Room.SendMessage(RoomUpdate);
        }
    }
}
